@include('admin.public.__head')
    <!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">

            <!-- Page Sidebar -->
            @include('admin.public.__left')
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>&nbsp;文章管理
                        </li>
                        <li>文章列表</li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Body -->
                <div class="page-body">
					<a href="{{url('admin/articleadd')}}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i>&nbsp;添加文章</a>
					<div class="row">
						<div class="col-xs-12">
							<div class="widget">
								<div class="widget-header">
									<span class="widget-caption">添加文章</span>
									<div class="widget-buttons">
										{!!strTostr($articles->links())!!}
									</div>
								</div>
								<div class="widget-body">
									<table class="table table-hover table-bordered">
										<thead>
											<tr>
												<th>ID</th>
												<th>文章标题</th>
                                                <th>作者</th>
												<th>所属导航</th>
												<th>是否推荐</th>
												<th>状态</th>
												<th>操作</th>
											</tr>
										</thead>
                                        @forelse ($articles as $vo)
										<tr>
											<td>{{$vo->id}}</td>
											<td>{{$vo->title}}</td>
											<td>{{$vo->members->nickname}}</td>
											<td>{{$vo->cates->catename}}</td>
											<td>
                                                @if ($vo->is_top == 1)
                                                已推荐
                                                @else
                                                未推荐
                                                @endif
                                            </td>
											<td>
                                                @if ($vo->status == 1)
                                                上架
                                                @else
                                                下架
                                                @endif
                                            </td>
											<td>
                                                @if ($vo->status == 1)
                                                <a href="#" class="btn btn-sm btn-default article-up" dataid="{{$vo->id}}" status="{{$vo->status}}">下架</a>
                                                @else
                                                <a href="#" class="btn btn-sm btn-success article-up" dataid="{{$vo->id}}">上架</a>
                                                @endif
												<a href="{{url('admin/articleedit', ['id' => $vo->id])}}" class="btn btn-sm btn-warning">编辑</a>
												<a href="#" class="btn btn-sm btn-danger article-del" dataid="{{$vo->id}}">删除</a>
                                                @if ($vo->is_top == 1)
                                                <a href="#" class="btn btn-sm btn-orange article-top" dataid="{{$vo->id}}" istop="{{$vo->is_top}}">取消推荐</a>
                                                @else
                                                <a href="#" class="btn btn-sm btn-blue article-top" dataid="{{$vo->id}}" istop="{{$vo->is_top}}">推荐</a>
                                                @endif
											</td>
										</tr>
                                        @empty
                                        <tr>
                                            <td colspan="7">没有文章</td>
                                        </tr>
                                        @endforelse
									</table>
								</div>
							</div>
						</div>
					</div>
                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->

        </div>
        <!-- /Page Container -->
        <!-- Main Container -->

    </div>

    @include('admin.public.__js')
    <script>
        $('.pagination').addClass('pagination-sm');

        $('.article-up').click(function () {
            var id = $(this).attr('dataid');
            var status = $(this).attr('status');
            if (status == 1) {
                var msg = '确定下架吗？';
            }else {
                var msg = '确定上架吗？';
            }
            layer.confirm(msg, {
                title:'上架操作',
                icon:3
            }, function (index) {
                layer.close(index);
                $.ajax({
                    url:"{{url('admin/articleup')}}",
                    type:'post',
                    data:{id:id, status:status},
                    dataType:'json',
                    success:function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg, {
                                icon:6,
                                time:2000
                            }, function () {
                                location.href = data.url;
                            });
                        }else {
                            layer.open({
                                title:'操作失败',
                                content:data.msg,
                                icon:5,
                                anim:6
                            });
                        }
                    }
                });
            });
            return false;
        });

        $('.article-top').click(function () {
            var id = $(this).attr('dataid');
            var is_top = $(this).attr('istop');
            if (is_top == 1) {
                var msg = '确定取消推荐？';
            }else {
                var msg = '确定推荐吗？';
            }
            layer.confirm(msg, {
                titlt:'推荐操作',
                icon:3
            }, function (index) {
                layer.close(index);
                $.ajax({
                    url:"{{url('admin/articleTop')}}",
                    type:'post',
                    data:{id:id, is_top:is_top},
                    dataType:'json',
                    success:function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg, {
                                icon:6,
                                time:2000
                            }, function () {
                                location.href = data.url;
                            });
                        }else {
                            layer.open({
                                title:'操作失败',
                                content:data.msg,
                                icon:5,
                                anim:6
                            });
                        }
                    }
                });
            });
            return false;
        });

        $('.article-del').click(function () {
            var id = $(this).attr('dataid');
            layer.confirm('确定删除吗？', {
                title:'删除文章',
                icon:3
            }, function (index) {
                layer.close(index);
                $.ajax({
                    url:"{{url('admin/articledel')}}",
                    type:'post',
                    data:{id:id},
                    dataType:'json',
                    success:function (data) {
                        if (data.code == 1) {
                            layer.msg(data.msg, {
                                icon:6,
                                time:2000
                            }, function () {
                                location.href = data.url;
                            });
                        }else {
                            layer.open({
                                title:'删除失败',
                                content:data.msg,
                                icon:5,
                                anim:6
                            });
                        }
                    }
                });
            });
            return false;
        });
    </script>
</body>
<!--  /Body -->
</html>
